namespace Resharper.Abstractions.CodeDom.Expressions.PostFixOperatorExpressions
{
  using System;
  using System.Diagnostics;
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi.CSharp.Tree;
  using Resharper.Abstractions.CodeDom.Expressions.LiteralExpressions;
  using Resharper.Abstractions.CodeDom.Expressions.PrimaryExpressions;

  /// <summary>
  /// 
  /// </summary>
  public enum PostFixOperatorType
  {
    /// <summary>The invalid field.</summary>
    Invalid,

    /// <summary>The plus plus field.</summary>
    PlusPlus,

    /// <summary>The minus minus field.</summary>
    MinusMinus
  }

  /// <summary>Defines the <see cref="LiteralExpression"/> class.</summary>
  public class PostFixOperatorExpression : Expression
  {
    #region Constructors and Destructors

    /// <summary>Initializes a new instance of the <see cref="LiteralExpression"/> class.</summary>
    /// <param name="literalExpression">The expression.</param>
    internal PostFixOperatorExpression([NotNull] IPostfixOperatorExpression literalExpression) : base(literalExpression)
    {
    }

    #endregion

    #region Properties

    /// <summary>
    /// Gets the operand.
    /// </summary>
    [CanBeNull]
    public PrimaryExpression Operand
    {
      get
      {
        var operand = this.InternalPostfixOperatorExpression.Operand;
        return operand != null ? new PrimaryExpression(operand) : null;
      }

      set
      {
        Debug.Assert(value != null, "value != null");

        this.InternalPostfixOperatorExpression.SetOperand(value.InternalPrimaryExpression);
      }
    }

    /// <summary>
    /// Gets the type of the post fix operator.
    /// </summary>
    public PostFixOperatorType OperatorType
    {
      get
      {
        switch (this.InternalPostfixOperatorExpression.PostfixOperatorType)
        {
          case PostfixOperatorType.INVALID:
            return PostFixOperatorType.Invalid;

          case PostfixOperatorType.PLUSPLUS:
            return PostFixOperatorType.PlusPlus;

          case PostfixOperatorType.MINUSMINUS:
            return PostFixOperatorType.MinusMinus;

          default:
            throw new ArgumentOutOfRangeException();
        }
      }
    }

    /// <summary>The literal expression field.</summary>
    [NotNull]
    internal IPostfixOperatorExpression InternalPostfixOperatorExpression
    {
      get
      {
        return (IPostfixOperatorExpression)this.InternalExpression;
      }
    }

    #endregion
  }
}